<?php
namespace Wxsdk;
use ErrorCode;
use Exception;
use think\Config;
class Wxsdk
{
    private $cappNum;//C端小程序资料

    public function __construct() {
        $config = new \app\api\model\Config();
        $this->cappNum = $config->getConfigGroup('cnum');
    }

    /**
     * 通过code请求接口获取openid
     * @param $code 用户登录code
     * @return mixed|string
     */
    public function getOpenid($code){
        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->cappNum['client_AppID']}&secret={$this->cappNum['client_AppSecret']}&js_code={$code}&grant_type=authorization_code";
        $result =file_get_contents($url);
        return json_decode($result,true);
    }
}

